﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;
using mshtml;
using WatiN.Core.Native.InternetExplorer;
using WatiN.Core.Native;
using System.Collections;
using HtmlAgilityPack;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Data;
using log4net;
using log4net.Config;

namespace PlayerStat
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Settings.AttachToBrowserTimeOut = 240;
            Settings.WaitUntilExistsTimeOut = 240;
            Settings.WaitForCompleteTimeOut = 240; 
            ILog logger = LogManager.GetLogger("scrape");

            //ScrapeSite ss = new ScrapeESPN();
            //int[] leagues = Leagues.GetLeagueIDs(Leagues.EnglandID);
            ScrapeSite ss = new ScrapeFR();
            int[] leagues = Leagues.GetLeagueIDs(Leagues.FranceID);
            //ScrapeSite ss = new ScrapeScot();
            //int[] leagues = Leagues.GetLeagueIDs(Leagues.ScotlandID);
            //ScrapeSite ss = new ScrapeGER();
            //int[] leagues = Leagues.GetLeagueIDs(Leagues.GermanID);
            //ScrapeSite ss = new ScrapeNorway();
            //int[] leagues = Leagues.GetLeagueIDs(Leagues.NorwayID);
            //ScrapeSite ss = new ScrapePor();
            //int[] leagues = Leagues.GetLeagueIDs(Leagues.PortugalID);
            //ScrapeSite ss = new ScrapeAus();
            //int[] leagues = Leagues.GetLeagueIDs(Leagues.AustriaID);
            //ScrapeSite ss = new ScrapeIre();
            //int[] leagues = Leagues.GetLeagueIDs(Leagues.IrelandID);
            //ScrapeSite ss = new ScrapeBel();
            //int[] leagues = Leagues.GetLeagueIDs(Leagues.BelgiumID);

            for (int i = 0; i < leagues.Length; i++)
            {
                ss.SetLeague(leagues[i]);


                while (true)
                {
                    try
                    {
                        if (ss.Scrape())
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToString());
                        logger.Error("Re-run Scrape()");
                    }
                }
            }

            System.Console.ReadLine();
        }
    }
}
